package com.baoxin.chenxixc4coach.fragments;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.baoxin.chenxixc4coach.AudioCourseActivity;
import com.baoxin.chenxixc4coach.R;
import com.baoxin.chenxixc4coach.SubjectAdvanceActivity;
import com.baoxin.chenxixc4coach.TestRangeActivity;
import com.baoxin.chenxixc4coach.adapter.MyViewPagerAdapter;
import com.baoxin.chenxixc4coach.fragments.teaching.VideoFragment;
import com.yusheng.w.tablayout.widgets.XTabLayout;

import java.util.ArrayList;
import java.util.List;

public class TeachingFragment extends BaseFragment implements XTabLayout.OnTabSelectedListener {

    private List<TitleFragment> fragments = new ArrayList<>(2);
    private VideoFragment videoFragment0;//教学视频
    private VideoFragment videoFragment1;//我的视频
    private XTabLayout mTabLayout;
    private ViewPager mViewPager;

    private TextView mYuyue;
    private TextView mTestRange;
    private TextView mAudio;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_teaching, container, false);
        mTabLayout = view.findViewById(R.id.tab_around);
        mViewPager = view.findViewById(R.id.view_pager);
        mYuyue = view.findViewById(R.id.yuyue);
        mTestRange = view.findViewById(R.id.arrange);
        mAudio = view.findViewById(R.id.audio);
        mYuyue.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(activity, SubjectAdvanceActivity.class);
                startActivity(intent);
            }
        });
        mTestRange.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(activity, TestRangeActivity.class);
                startActivity(intent);
            }
        });
        mAudio.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(activity, AudioCourseActivity.class);
                startActivity(intent);
            }
        });

        videoFragment0 = new VideoFragment();
        videoFragment1 = new VideoFragment();
        videoFragment0.setType(0);
        videoFragment1.setType(1);

        fragments.add(videoFragment0);
        fragments.add(videoFragment1);
        mViewPager.setAdapter(new MyViewPagerAdapter(getChildFragmentManager(), fragments));
        mTabLayout.setupWithViewPager(mViewPager);
        mTabLayout.setOnTabSelectedListener(this);
        return view;
    }


    @Override
    public void onTabSelected(XTabLayout.Tab tab) {
        mViewPager.setCurrentItem(tab.getPosition());
    }

    @Override
    public void onTabUnselected(XTabLayout.Tab tab) {

    }

    @Override
    public void onTabReselected(XTabLayout.Tab tab) {

    }
}
